<?php

// Acceso restringido
defined('JL') or die('Acceso restringido');
define('RESPONSE_CODE_ALERT', 1);
define('RESPONSE_CODE_ERROR', 2);
define('RESPONSE_CODE_INFO', 3);
define('RESPONSE_CODE_OK', 4);

/**
 * Clase Config para creacion de variables globales
 */
class Config implements ArrayAccess {

    private $vars;
    private static $instance;

    private function __construct() {
        $this->vars = array();
    }

    function set($key, $var) {
        if (isset($this->vars[$key]) == true) {
            throw new Exception('Unable to set var <b>`' . $key . '`</b>, Already set.');
        }

        $this->vars[$key] = $var;
        return true;
    }

    function get($key) {
        if (isset($this->vars[$key]) == false) {
            return null;
        }

        return $this->vars[$key];
    }

    function remove($var) {
        unset($this->vars[$key]);
    }

    function offsetExists($offset) {
        return isset($this->vars[$offset]);
    }

    function offsetGet($offset) {
        return $this->get($offset);
    }

    function offsetSet($offset, $value) {
        $this->set($offset, $value);
    }

    function offsetUnset($offset) {
        unset($this->vars[$offset]);
    }

    public static function getInstance() {
        if (!isset(self::$instance)) {
            $c = __CLASS__;
            self::$instance = new $c;
        }

        return self::$instance;
    }

}